package com.fan.shop.businesslogic;

import org.apache.log4j.Logger;

import com.fan.shop.domain.Store;
import com.fan.shop.global.ShopGlobalVariables;
import com.fan.shop.process.ProcExec;
import com.fan.shop.services.StoreService;

public class StoreDeleteProcess extends ProcExec<Integer> {

	private String storeCode;
	private static Logger logger = Logger.getLogger(StoreDeleteProcess.class);
	private StoreService storeService;

	public String getStoreCode() {
		return storeCode;
	}

	public void setStoreCode(String storeCode) {
		this.storeCode = storeCode;
	}

	public static Logger getLogger() {
		return logger;
	}

	public static void setLogger(Logger logger) {
		StoreDeleteProcess.logger = logger;
	}

	public StoreService getStoreService() {
		return storeService;
	}

	public void setStoreService(StoreService storeService) {
		this.storeService = storeService;
	}

	@Override
	public Integer processImpl() {
		if (storeService.hasStore(storeCode)) {
			Store store = storeService.getStore(storeCode);
			storeService.deleteStore(store);
			return ShopGlobalVariables.SUCCESS;
		} else {
			setErrorMessage("Store: " + storeCode + " doesn't exist!");
			return ShopGlobalVariables.FAILED;
		}
	}

}
